package com.sicau.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sicau.common.annotation.Log;
import com.sicau.common.core.controller.BaseController;
import com.sicau.common.core.domain.AjaxResult;
import com.sicau.common.enums.BusinessType;
import com.sicau.system.domain.BMessageUser;
import com.sicau.system.service.IBMessageUserService;
import com.sicau.common.utils.poi.ExcelUtil;
import com.sicau.common.core.page.TableDataInfo;

/**
 * 消息和用户关联Controller
 * 
 * @author ruoyi
 * @date 2022-03-19
 */
@RestController
@RequestMapping("/message/user")
public class BMessageUserController extends BaseController
{
    @Autowired
    private IBMessageUserService bMessageUserService;

    /**
     * 查询消息和用户关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(BMessageUser bMessageUser)
    {
        startPage();
        List<BMessageUser> list = bMessageUserService.selectBMessageUserList(bMessageUser);
        return getDataTable(list);
    }

    /**
     * 导出消息和用户关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @Log(title = "消息和用户关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BMessageUser bMessageUser)
    {
        List<BMessageUser> list = bMessageUserService.selectBMessageUserList(bMessageUser);
        ExcelUtil<BMessageUser> util = new ExcelUtil<BMessageUser>(BMessageUser.class);
        util.exportExcel(response, list, "消息和用户关联数据");
    }

    /**
     * 获取消息和用户关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return AjaxResult.success(bMessageUserService.selectBMessageUserByMessageId(messageId));
    }

    /**
     * 新增消息和用户关联
     */
    @PreAuthorize("@ss.hasPermi('system:user:add')")
    @Log(title = "消息和用户关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BMessageUser bMessageUser)
    {
        return toAjax(bMessageUserService.insertBMessageUser(bMessageUser));
    }

    /**
     * 修改消息和用户关联
     */
    @PreAuthorize("@ss.hasPermi('system:user:edit')")
    @Log(title = "消息和用户关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BMessageUser bMessageUser)
    {
        return toAjax(bMessageUserService.updateBMessageUser(bMessageUser));
    }

    /**
     * 删除消息和用户关联
     */
    @PreAuthorize("@ss.hasPermi('system:user:remove')")
    @Log(title = "消息和用户关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(bMessageUserService.deleteBMessageUserByMessageIds(messageIds));
    }
}
